# -*- coding: utf-8 -*-

import json, os


class DbType():
    ORACLE = 1
    POSTGRES = 2


class Config(object):
    """配置文件管理"""
    __fn = os.getcwd() + "\\config.dat"
    __encrypt = False
    link_map = {}

    def load_from_file(self):
        f = open(self.__fn, 'rt', encoding='utf-8')
        res = f.read()
        self.link_map = json.loads(res)
        f.close()

    def save_to_file(self):
        s = json.dumps(self.link_map, ensure_ascii=False)
        f = open(self.__fn, 'wt', encoding='utf-8')
        f.write(s)
        f.close()

    def __init__(self, encrypt = False):
        self.__encrypt = encrypt

        if os.path.exists(self.__fn):
            self.load_from_file()
        else:
            self.link_map['default'] = {
                "dbtype": DbType.ORACLE,
                "addr": "10.19.94.29",
                "port": "1521",
                "db": "orcl",
                "user": "his_gr",
                "pwd": "hiscss",
            }
            self.save_to_file()